using System;

namespace GURUCORE.Framework.DataAccess.ORMapping.CriteriaMapping
{
	public class Criteria : ICriteria
	{
		private Expression m_oCondition;
        public Expression Condition
        {
            get
            {
                return m_oCondition;
            }
            set
            {
                m_oCondition = value;
            }
        }

		private Order[] m_arrOrders;
        public Order[] Orders
        {
            get
            {
                return m_arrOrders;
            }
            set
            {
                m_arrOrders = value;
            }
        }

		private int m_nFirstRow;
        public int FirstRow
        {
            get
            {
                return m_nFirstRow;
            }
        }

        private int m_nRowCount;
        public int RowCount
        {
            get
            {
                return m_nRowCount;
            }
        }
        



		public Criteria(Expression p_oCondition, params Order[] p_arrOrders)
		{
			m_oCondition = p_oCondition;
			m_arrOrders = p_arrOrders;
			m_nFirstRow = m_nRowCount = -1;
		}

		public Criteria(Expression p_oCondition, int p_nFirstRow, int p_nRowCount, params Order[] p_arrOrders)
		{
			m_oCondition = p_oCondition;
			m_arrOrders = p_arrOrders;
			m_nFirstRow = p_nFirstRow;
			m_nRowCount = p_nRowCount;
		}

		

		

		public string GetOrdersString(IExpressionMaker p_oExpressionMaker)
		{
			string sResult = string.Empty;
			if ((m_arrOrders != null) && (m_arrOrders.Length > 0))
			{
				foreach (Order oOrder in m_arrOrders)
				{
					sResult += oOrder.ToExpressionString(p_oExpressionMaker) + ",";
				}
				sResult = sResult.Substring(0,sResult.Length - 1);
			}
			return sResult;
		}

		public string GetReversedOrdersString(IExpressionMaker p_oExpressionMaker)
		{
			string sResult = string.Empty;
			if (m_arrOrders != null)
			{
				foreach (Order oOrder in m_arrOrders)
				{
					Order oReversedOrder = oOrder.ReversedOrder;
					sResult += oReversedOrder.ToExpressionString(p_oExpressionMaker) + ",";
				}
				sResult = sResult.Substring(0,sResult.Length - 1);
			}
			return sResult;
		}

		
	}

    
}
